package com.oocl.products.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.oocl.products.pojo.Product;
import com.oocl.products.pojo.Store;
import com.oocl.products.service.ProductService;
import com.oocl.products.service.StoreService;
import com.oocl.products.service.factory.ProductServiceFactory;
import com.oocl.products.service.factory.StoreServiceFactory;

/**
 * Servlet implementation class ListServlet
 */
public class ListServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private StoreService storeService;
	private ProductService productService;
	
	public ListServlet() {
		storeService = StoreServiceFactory.getInstance();
		productService = ProductServiceFactory.getInstance();
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String sidStr = request.getParameter("sid");
		Integer sid = 1;
		if(sidStr!=null){
			sid = Integer.parseInt(sidStr);
		}
		List<Store> stores = storeService.queryAllStore();
		request.setAttribute("stores", stores);
		request.setAttribute("sid", sid);
		
		List<Product> products = productService.queryAllProductBySid(sid);
		request.setAttribute("products", products);
		request.getRequestDispatcher("list.jsp").forward(request, response);;
		
	}


}
